package telas;

import java.awt.EventQueue;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.text.MaskFormatter;

import classes.Funcionario;
import classes.Gerente;
import classes.Vendedor;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.ParseException;

import javax.swing.ImageIcon;
import javax.swing.JFormattedTextField;
import javax.swing.JRadioButton;

public class FuncionarioTelaPrincipal extends JFrame {

	private JPanel contentPane;
	private JTextField tfNome;
	private JTextField tfRg;
	private JTextField tfEndereco;
	private JTextField tfCidade;
	private JLabel lblNewLabel;
	private JLabel lblEndereo;
	private JLabel lblCidade;
	private JLabel lblCidade_1;
	private JLabel lblUf;
	private JComboBox<String> cbUf;
	private JTextField tfSalario;
	private JLabel lblSalario;
	private JFormattedTextField ftfCpf;
	private MaskFormatter mascaraCPF;
	private JLabel lblNewLabel_1;
	private JTextField tfDepartamento;
	private JTextField tfHorario;
	private JTextField tfFuncionario;

	private JRadioButton rbVendedor;
	private JRadioButton rbGerente;
	private JLabel lblNewLabel_4;
	private JLabel lblNewLabel_5;
	private JTextField tfMeta;
	private JTextField tfComissao;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FuncionarioTelaPrincipal frame = new FuncionarioTelaPrincipal();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * 
	 * @throws ParseException
	 */
	public FuncionarioTelaPrincipal() throws ParseException {

		mascaraCPF = new MaskFormatter("###.###.###-##");
		setIconImage(Toolkit
				.getDefaultToolkit()
				.getImage(
						FuncionarioTelaPrincipal.class
								.getResource("/com/sun/java/swing/plaf/windows/icons/Computer.gif")));
		setTitle("Cadastro de Funcionario");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 410, 420);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		tfNome = new JTextField();
		tfNome.setBounds(81, 11, 279, 20);
		tfNome.setColumns(10);
		contentPane.setLayout(null);
		contentPane.add(tfNome);

		tfRg = new JTextField();
		tfRg.setColumns(10);
		tfRg.setBounds(81, 42, 279, 20);
		contentPane.add(tfRg);

		tfEndereco = new JTextField();
		tfEndereco.setColumns(10);
		tfEndereco.setBounds(81, 73, 279, 20);
		contentPane.add(tfEndereco);

		tfCidade = new JTextField();
		tfCidade.setColumns(10);
		tfCidade.setBounds(81, 104, 279, 20);
		contentPane.add(tfCidade);

		lblNewLabel = new JLabel("Nome:");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(25, 14, 46, 14);
		contentPane.add(lblNewLabel);

		lblEndereo = new JLabel("Rg:");
		lblEndereo.setHorizontalAlignment(SwingConstants.RIGHT);
		lblEndereo.setBounds(35, 45, 33, 14);
		contentPane.add(lblEndereo);

		lblCidade = new JLabel("Endere\u00E7o:");
		lblCidade.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCidade.setBounds(10, 76, 61, 14);
		contentPane.add(lblCidade);

		lblCidade_1 = new JLabel("Cidade:");
		lblCidade_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCidade_1.setBounds(25, 107, 46, 14);
		contentPane.add(lblCidade_1);

		lblUf = new JLabel("UF:");
		lblUf.setHorizontalAlignment(SwingConstants.RIGHT);
		lblUf.setBounds(25, 204, 46, 14);
		contentPane.add(lblUf);

		cbUf = new JComboBox<String>();
		cbUf.setModel(new DefaultComboBoxModel<String>(new String[] { "AC",
				"PR" }));
		cbUf.setBounds(81, 200, 61, 22);
		contentPane.add(cbUf);

		JButton btnNewButton = new JButton("Clique Aqui");
		btnNewButton.setToolTipText("Clique aqui para salvar");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				Object obj = new Object();

				if (rbGerente.isSelected()) {
					
					Gerente gerente = new Gerente();

					gerente.setNome(tfNome.getText());
					gerente.setRg(tfRg.getText());
					gerente.setEndereco(tfRg.getText());
					gerente.setCidade(tfCidade.getText());
					gerente.setSalario(Double.valueOf(tfSalario.getText()));
					gerente.setUf(cbUf.getSelectedItem().toString());
					gerente.setHorario(tfHorario.getText());
					gerente.setMeta(tfMeta.getText());
					gerente.setComissao(tfComissao.getText());
					gerente.statusFuncionario();

				} else if (rbVendedor.isSelected()) {
					
					Vendedor vendedor = new Vendedor();
					
					vendedor.setNome(tfNome.getText());
					vendedor.setRg(tfRg.getText());
					vendedor.setEndereco(tfRg.getText());
					vendedor.setCidade(tfCidade.getText());
					vendedor.setSalario(Double.valueOf(tfSalario.getText()));
					vendedor.setUf(cbUf.getSelectedItem().toString());
					vendedor.statusFuncionario();
				}
			}
		});
		btnNewButton.setBounds(25, 320, 117, 23);
		contentPane.add(btnNewButton);

		tfSalario = new JTextField();
		tfSalario.addKeyListener(new KeyAdapter() {
			public void keyReleased(KeyEvent arg0) {
				tfSalario.setText(tfSalario.getText().replace(",", "."));
			}
		});
		tfSalario.setBounds(81, 135, 279, 20);
		contentPane.add(tfSalario);
		tfSalario.setColumns(10);

		lblSalario = new JLabel("Salario:");
		lblSalario.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSalario.setBounds(25, 138, 46, 14);
		contentPane.add(lblSalario);

		ftfCpf = new JFormattedTextField(mascaraCPF);
		ftfCpf.setBounds(81, 166, 279, 20);
		contentPane.add(ftfCpf);

		lblNewLabel_1 = new JLabel("CPF:");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(25, 169, 46, 14);
		contentPane.add(lblNewLabel_1);

		rbGerente = new JRadioButton("Gerente");
		rbGerente.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rbVendedor.setSelected(false);

				tfDepartamento.setEnabled(true);
				tfHorario.setEnabled(true);
				tfFuncionario.setEnabled(true);
				tfMeta.setEnabled(true);
				tfComissao.setEnabled(true);

			}
		});
		rbGerente.setBounds(25, 264, 109, 23);
		contentPane.add(rbGerente);

		rbVendedor = new JRadioButton("Vendedor");

		rbVendedor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				rbGerente.setSelected(false);
				tfDepartamento.setEnabled(false);
				tfHorario.setEnabled(false);
				tfFuncionario.setEnabled(false);
				tfMeta.setEnabled(false);
				tfComissao.setEnabled(false);

				tfDepartamento.setText("");
				tfHorario.setText("");
				tfFuncionario.setText("");

			}
		});

		rbVendedor.setBounds(25, 290, 109, 23);
		contentPane.add(rbVendedor);

		tfDepartamento = new JTextField();
		tfDepartamento.setBounds(232, 231, 140, 20);
		contentPane.add(tfDepartamento);
		tfDepartamento.setColumns(10);

		JLabel lblDepartaento = new JLabel("Departameno:");
		lblDepartaento.setBounds(152, 234, 70, 14);
		contentPane.add(lblDepartaento);

		JLabel lblNewLabel_2 = new JLabel("Hor\u00E1rio:");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_2.setBounds(176, 264, 46, 14);
		contentPane.add(lblNewLabel_2);

		JLabel lblNewLabel_3 = new JLabel("Funcionario:");
		lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_3.setBounds(152, 295, 70, 14);
		contentPane.add(lblNewLabel_3);

		tfHorario = new JTextField();
		tfHorario.setBounds(232, 262, 140, 20);
		contentPane.add(tfHorario);
		tfHorario.setColumns(10);

		tfFuncionario = new JTextField();
		tfFuncionario.setBounds(232, 291, 140, 20);
		contentPane.add(tfFuncionario);
		tfFuncionario.setColumns(10);


		lblNewLabel_4 = new JLabel("Meta:");
		lblNewLabel_4.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_4.setBounds(176, 324, 46, 14);
		contentPane.add(lblNewLabel_4);

		lblNewLabel_5 = new JLabel("Comiss\u00E3o:");
		lblNewLabel_5.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_5.setBounds(161, 353, 61, 14);
		contentPane.add(lblNewLabel_5);
		
		tfMeta = new JTextField();
		tfMeta.setBounds(232, 321, 140, 20);
		contentPane.add(tfMeta);
		tfMeta.setColumns(10);
		
		tfComissao = new JTextField();
		tfComissao.setBounds(232, 350, 140, 20);
		contentPane.add(tfComissao);
		tfComissao.setColumns(10);
		
		tfDepartamento.setEnabled(false);
		tfHorario.setEnabled(false);
		tfFuncionario.setEnabled(false);
		tfMeta.setEnabled(false);
		tfComissao.setEnabled(false);

	}
}
